package com.ruoyi.web.controller.marry;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.marry.domain.TUser;
import com.ruoyi.marry.service.ITUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户管理Controller
 *
 * @author user_marry
 * @date 2020-11-23
 */
@RestController
@RequestMapping("/marry/user")
public class TUserController extends BaseController {

    @Autowired
    private ITUserService tUserService;

    /**
     * 查询用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('marry:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(TUser tUser) {
        startPage();
        List<TUser> list = tUserService.selectTUserList(tUser);
        return getDataTable(list);
    }

    /**
     * 导出用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('marry:user:export')")
    @Log(title = "用户管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TUser tUser) {
        List<TUser> list = tUserService.selectTUserList(tUser);
        ExcelUtil<TUser> util = new ExcelUtil<TUser>(TUser.class);
        return util.exportExcel(list, "tuser");
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('marry:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(tUserService.selectTUserById(id));
    }

    /**
     * 新增保存用户管理
     */
    @PreAuthorize("@ss.hasPermi('marry:user:add')")
    @Log(title = "用户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TUser tUser) {
        return toAjax(tUserService.insertTUser(tUser));
    }

    /**
     * 修改用户管理
     */
    @PreAuthorize("@ss.hasPermi('marry:user:edit')")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TUser tUser) {
        return toAjax(tUserService.updateTUser(tUser));
    }

    /**
     * 删除用户管理
     */
    @PreAuthorize("@ss.hasPermi('marry:user:remove')")
    @Log(title = "用户管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tUserService.deleteTUserByIds(ids));
    }
}
